package net.linxuehua.server.dto;/**
 * @author chenyan
 * @createTime 2021/1/11 14:19
 * @description description
 */

import cn.hutool.crypto.SecureUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.linxuehua.server.po.User;

@Data
public class UserDTO {
    @ApiModelProperty(value = "userId", dataType = "Integer", required = false)
    private Integer userId;

    @ApiModelProperty(value = "用户名", dataType = "String", required = false)
    private String userName;

    @ApiModelProperty(value = "密码", dataType = "String", required = false)
    private String password;

    @ApiModelProperty(value = "头像", dataType = "String", required = false)
    private String userImg;


    public User toUser() {
        User user = new User();
        if (this.getUserId() != null && this.getUserId() != 0) {
            user.setUserId(this.getUserId());
        }
        user.setUserName(this.userName);
        user.setPassword(SecureUtil.md5(this.getPassword()));
        user.setUserImg(this.userImg);
        return user;
    }

}
